package com.service.business.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.service.business.product.controller.rep.ProductHrComboPageRep;
import com.service.business.product.controller.rep.ProductLockPageRep;
import com.service.business.product.controller.rep.ProductPayTypeRep;
import com.service.business.product.service.ProductLockComboService;
import com.service.business.support.Language;
import com.service.business.utils.DateUtil;
import com.service.core.rest.request.PageRequest;
import com.service.core.rest.response.CommonPageRep;
import com.service.dao.enums.CoinsEnum;
import com.service.dao.enums.CommonStatusEnums;
import com.service.dao.enums.HrComboTypeEnum;
import com.service.dao.mapper.ProductLockComboMapper;
import com.service.dao.model.ProductHrCombo;
import com.service.dao.model.ProductLockCombo;
import com.service.utility.modelmapper.ModelMapperUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@Service("productLockComboService")
public class ProductLockServiceImpl extends ServiceImpl<ProductLockComboMapper, ProductLockCombo> implements ProductLockComboService {

	@Override
	public CommonPageRep<ProductLockPageRep> pageLockCombo(CoinsEnum coin, PageRequest pageRequest) {
		Page<ProductLockCombo> page = PageHelper.startPage(pageRequest.getPageNo(), pageRequest.getPageSize());
		list(new QueryWrapper<ProductLockCombo>().lambda()
				.eq(ProductLockCombo::getCoinsId,coin.getCode())
				.eq(ProductLockCombo::getComboStatus, CommonStatusEnums.ACTIVE.getCode())
				.orderByAsc(ProductLockCombo::getLockDay)
		);
		List<ProductLockPageRep> resultList = page.getResult().stream().map(item -> this.buildProductLockPageRep(item)).collect(Collectors.toList());
		return CommonPageRep.buildResultRep(page, resultList);
	}

	private ProductLockPageRep buildProductLockPageRep(ProductLockCombo lockCombo) {
		ProductLockPageRep rep = ModelMapperUtil.getStrictModelMapper().map(lockCombo, ProductLockPageRep.class);
		rep.setComboName(lockCombo.getComboName());
		rep.setLockDay(lockCombo.getLockDay());
		rep.setId(lockCombo.getId());
		rep.setLockLimit(lockCombo.getLockLimit());
		rep.setYearInterestRate(lockCombo.getYearInterestRate());
		return rep;
	}
}
